package com.century.sjt.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.century.sjt.R;
import com.century.sjt.entity.DayTransaction;

import java.util.List;

/**
 * Created by asus on 2016/9/7.
 * 日结算 二级菜单适配器
 */
public class payDayTransationAdapter extends BaseExpandableListAdapter {

    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private List<DayTransaction> mDataList;
    private Handler mHandler;
    public payDayTransationAdapter(Context context, List<DayTransaction> mList,Handler mHandler) {
        this.mContext = context;
        this.mDataList = mList;
        this.mHandler = mHandler;
        mLayoutInflater = LayoutInflater.from(context);
    }
    /**
     * 取得分组数
     */
    @Override
    public int getGroupCount() {
        return mDataList.size();
    }

    /**
     * 取得指定分组的子元素数
     */
    @Override
    public int getChildrenCount(int i) {
        return mDataList.get(i).getmDataList().size();
    }
    /**
     * 取得与给定分组关联的数据
     */
    @Override
    public Object getGroup(int i) {
        return mDataList.get(i);
    }
    /**
     * 取得与给定分组关联子元素数的数据
     */
    @Override
    public Object getChild(int i, int i1) {
        return mDataList.get(i).getmDataList().get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View convertView, ViewGroup viewGroup) {
        GroupHolder groupHolder = null;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.pay_day_transaction_gropitem, null);
            groupHolder = new GroupHolder();
            groupHolder.groupImg = (TextView) convertView.findViewById(R.id.img_indicator);
            groupHolder.groupText = (TextView) convertView.findViewById(R.id.tv_group_text);
            Typeface iconfont = Typeface.createFromAsset(mContext.getAssets(), "iconfont.ttf");
            groupHolder.groupImg.setTypeface(iconfont);
            convertView.setTag(groupHolder);
        }else {
            groupHolder = (GroupHolder) convertView.getTag();
        }

        groupHolder.groupText.setText(mDataList.get(i).getmDay());
        if (mDataList.get(i).isSelsct()){
            groupHolder.groupImg.setText(mContext.getResources().getString(R.string.icon_receive));
        }else {
            groupHolder.groupImg.setText(mContext.getResources().getString(R.string.icon_drop_down));
        }
        return convertView;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View convertView, ViewGroup viewGroup) {
        ChildHolder childHolder = null;
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.pay_day_transaction_childitem, null);
            childHolder = new ChildHolder();
            childHolder.childImg = (TextView) convertView.findViewById(R.id.img_child);
            childHolder.childText = (TextView) convertView.findViewById(R.id.tv_child_text);
            convertView.setTag(childHolder);
        }else {
            childHolder = (ChildHolder) convertView.getTag();
        }
//        childHolder.childImg.setBackgroundResource(childMap.get(groupPosition).ge/*t(childPosition).getMarkerImgId());
//        childHolder.childText.setText(childMap.get(groupPosition).get(childPosition).getTitle());*/
        childHolder.childText.setText(mDataList.get(i).getmDataList().get(i1).getTxDate());
        childHolder.childImg.setText(mDataList.get(i).getmDataList().get(i1).getTxAmt()+"元");
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }

    private class GroupHolder
    {
        TextView groupImg;
        TextView groupText;
    }
    private class ChildHolder
    {
        TextView childImg;
        TextView childText;
    }
}
